<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日志管理</title>
    <link rel="stylesheet" type="text/css" href="/static/hplus/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/hplus/css/style.css">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <style type="text/css">
        .form-control {width: 220px;}
        .ttd {width: 250px;text-align: center;}
        .ttb {width: 80px;text-align: center;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <form action="/logs/lists" method="get">
                        <table style="width: 100%;padding: 0;border: none">
                            <tr>
                                <td colspan="100" class="tab_a">
                                    {foreach $modules as $k=>$m}
                                    <a href="javascript:;" data-href="{if($k!==$module)}/logs/lists?module={$k}{/if}" class="btn{if($k===$module)} btn-success{/if}">{$m}</a>
                                    {/foreach}
                                </td>
                            </tr>
                            <tr>
                                <td class="ttd">
                                    <input type="text" name="keyword" placeholder="日志内容" class="input-sm form-control" value="{$param.keyword??''}" autocomplete="off">
                                    <input type="hidden" name="module" value="{$module}">
                                </td>
                                <td class="ttb"><input type="submit" class="btn btn-sm btn-primary" value="搜索"></td>
                                <td class="ttb">
                                    <a href="javascript:;" class="btn btn-sm btn-info" data-action="delAll" data-module="{$module}">批量删除</a>
                                </td>
                                <td class="ttb">
                                    <a href="javascript:;" data-module="{$module}" data-tip="{$modules[$module]}" class="btn btn-sm btn-default">清空日志</a>
                                </td>
                                <td>&nbsp;</td>
                            </tr>
                        </table>
                    </form>
                </div>
                <div class="ibox-content">
                    <table id="treeTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/hplus/js/jquery.min.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/layer/layer.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/royui/royui.min.js?v={php}echo time(){/php}"></script>
<script>
    $(function () {
        let r = new royui();
        r.treeTable({
            elem: '#treeTable',
            //data: $data,
            url: '/logs/lists?module={$module}',
            method: 'post',
            //is_cache: false,
            count: {$count},
            total_page: true,
            checkbox: true,
            paging: true,
            pages: {$pages},
            show_pages: 5,
            cols: [
                {
                    field: 'msg',
                    title: '日志内容',
                    style: 'max-width: 500px;word-break:break-all;padding-right:15px'
                },
                {
                    field: 'time',
                    title: '时间',
                    title_style: 'cursor:pointer',
                    is_sort: true
                },
                {
                    field: 'type',
                    title: '类型',
                    title_style: 'cursor:pointer',
                    is_sort: true
                },
                {
                    title: '操作',
                    action: [{matter: 'del', url: '/logs/del'}]
                }
            ]
        })
        $('.tab_a a').click(function () {
            location.href = $(this).data('href')
        })
        let $body = $('body')
        $body.on('click', 'a[data-tip]', function () {
            let $module = $(this).data('module'), $tip = $(this).data('tip')
            layer.confirm('确实要清空' + $tip + '吗？', {icon: 3}, function () {
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '/logs/clearLog',
                    data: {'module': $module},
                    success: function (data) {
                        if (data.code === 200) {
                            layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(data.message, {icon: 5})
                        }
                    }
                })
            })
        })
        $body.on('click', 'a[data-action]', function () {
            let $ids = [];
            let $action = $(this).data('action'), $module = $(this).data('module');;
            if ($action.indexOf('All')) {
                $('.royui_checkbox').each(function () {
                    if ($(this).is(':checked')) {
                        $ids.push($(this).val())
                    }
                });
            }
            if ($ids.length === 0) {
                layer.msg('请选择要删除的项');
                return false
            }
            layer.confirm('确实要删除吗？', {icon: 3}, function () {
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '/logs/delAll',
                    data: {'ids': $ids, 'module': $module},
                    success: function (data) {
                        if (data.code === 200) {
                            layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(data.message, {icon: 5})
                        }
                    }
                })
            })
        })
    });
</script>
</html>
